<script lang="ts" setup>
import { reactive, onMounted } from 'vue'
import { ElMessage } from 'element-plus';

// do not use same name with ref
const formData = reactive({
    form: {
        txbl: '',
        fxsybl: '',
        txzded: '',
        mytxcs: '',
        txxf: '',
        da1: '',
        da2: '',
    }

})

const onSubmit = () => {
    console.log('submit!')
}

import axios from 'axios'
const getTxpz = () => {
    //参考接口文档，请求用户数据
    axios.get("/api/txpz/").then((response) => {
        console.log(response, "网站信息数据")
        //更新用户数据
        formData.form = response.data[0]
        console.log(formData.form, "接收网站信息数据")
    })
}
onMounted(() => {
    getTxpz()
})
const updateTxpz = () => {
    console.log(formData.form, "<-----1111修改网站信息数据")
    axios.patch("/api/txpz/1/",
        formData.form,
        { headers: { "Content-Type": "application/json" } }   //application/json
    ).then((response) => {
        console.log(response, "<-----修改网站信息数据")
        // 更新用户数据
        formData.form = response.data
        //console.log(response.data[0], "<------接收网站信息数据")
        // 重新获取数据
        //getWzxx()
        ElMessage({
            type: "success",
            message: "信息保存成功"
        })
    })

}

</script>

<template>
    <el-form :model="formData.form" label-width="auto" style="max-width: 600px">
        <el-form-item label="提现比例">
            <el-input v-model="formData.form.txbl" />
            <h3>提现一元人民币所需的票数</h3>
        </el-form-item>
        <el-form-item label="分销收益比例">
            <el-input v-model="formData.form.fxsybl" />
            <h3>商品分销收益换成金币比例</h3>
        </el-form-item>
        <el-form-item label="提现最低额度（元）">
            <el-input v-model="formData.form.txzded" />
            <h3>可提现的最小额度，低于该额度无法提现</h3>
        </el-form-item>
        <el-form-item label="每月提现期">
            <el-col :span="11">
                <el-input v-model="formData.form.da1" style="width: 100%" />
            </el-col>
            <el-col :span="2" class="text-center">
                <span class="text-gray-500">-</span>
            </el-col>
            <el-col :span="11">
                <el-input v-model="formData.form.da2" />
            </el-col>
            <h3>每月提现时间段，不在该时间段无法提现</h3>
        </el-form-item>
        <el-form-item label="每月提现次数">
            <el-input v-model="formData.form.mytxcs" />
            <h3>每月最大提现次数，0表示不限制</h3>
        </el-form-item>
        <el-form-item label="非主播提现所需消费">
            <el-input v-model="formData.form.txxf" />
            <h3>提现最低消费金额数，0表示不限制</h3>
        </el-form-item>

        <el-form-item>
            <el-button type="primary" @click="updateTxpz">保存</el-button>
        </el-form-item>
    </el-form>
</template>

<style scoped>
.el-form-item h3 {
    color: #999;
    font-size: 14px;
}

.el-button {
    margin-left: 155px;
}
</style>